using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VKSFGK
    {
        public DataRow Convert2KSFGK(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryKSFGK(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["KSFMANDANT"] = " ".PadRight(2 ); 
         dwReturn["KSFKTAB"] = " ".PadRight(5 ); 
         dwReturn["KSFZTR"] = " ".PadRight(1 ); 
         dwReturn["KSFHKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["KSFHKST"] = " ".PadRight(4 ); 
         dwReturn["KSFAKSTKRS"] = " ".PadRight(2 ); 
         dwReturn["KSFAKST"] = " ".PadRight(4 ); 
         dwReturn["KSFPROGRP"] = " ".PadRight(3 ); 
         dwReturn["KSFLFDNR"] = " ".PadRight(2 ); 
         dwReturn["KSFAENZL"] = " ".PadRight(0 ); 
         dwReturn["KSFAENB"] = " ".PadRight(8 ); 
         dwReturn["KSFAEND"] = " ".PadRight(0 ); 
         dwReturn["KSFNEUB"] = " ".PadRight(8 ); 
         dwReturn["KSFNEUD"] = " ".PadRight(0 ); 
         dwReturn["KSFVRSATZ01"] = " ".PadRight(0 ); 
         dwReturn["KSFVRSATZ02"] = " ".PadRight(0 ); 
         dwReturn["KSFVRSATZ03"] = " ".PadRight(0 ); 
         dwReturn["KSFVRSATZ04"] = " ".PadRight(0 ); 
         dwReturn["KSFVRSATZ05"] = " ".PadRight(0 ); 
         dwReturn["KSFBAS"] = " ".PadRight(1 ); 
         dwReturn["KSFPROZ"] = " ".PadRight(1 ); 
         dwReturn["KSFSTUFE"] = " ".PadRight(2 ); 
         dwReturn["KSFPMG01"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG02"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG03"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG04"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG05"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG06"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG07"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG08"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG09"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG10"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG11"] = " ".PadRight(0 ); 
         dwReturn["KSFPMG12"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN01"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN02"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN03"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN04"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN05"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN06"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN07"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN08"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN09"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN10"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN11"] = " ".PadRight(0 ); 
         dwReturn["KSFPLAN12"] = " ".PadRight(0 ); 
         dwReturn["KSFIST01"] = " ".PadRight(0 ); 
         dwReturn["KSFIST02"] = " ".PadRight(0 ); 
         dwReturn["KSFIST03"] = " ".PadRight(0 ); 
         dwReturn["KSFIST04"] = " ".PadRight(0 ); 
         dwReturn["KSFIST05"] = " ".PadRight(0 ); 
         dwReturn["KSFIST06"] = " ".PadRight(0 ); 
         dwReturn["KSFIST07"] = " ".PadRight(0 ); 
         dwReturn["KSFIST08"] = " ".PadRight(0 ); 
         dwReturn["KSFIST09"] = " ".PadRight(0 ); 
         dwReturn["KSFIST10"] = " ".PadRight(0 ); 
         dwReturn["KSFIST11"] = " ".PadRight(0 ); 
         dwReturn["KSFIST12"] = " ".PadRight(0 ); 
         dwReturn["KSFBEM"] = " ".PadRight(70 ); 
         dwReturn["KSFFILLER"] = " ".PadRight(111 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapKSFGK(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveKSFGK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryKSFGK(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapKSFGK(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertKSFGK(dwLocal, ITXDBVERSION);
            }
            UpdateKSFGK(dwLocal);
        }
        public void InsertKSFGK(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO KSFGK(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryKSFGK(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM KSFGK WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM KSFGK  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "KSFGK";
            Return = Result;
            return Return;
        }
        public void DeleteKSFGK(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM KSFGK   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateKSFGK(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE KSFGK SET "
                    +"KSFMANDANT= :KSFMANDANT,"
                    +"KSFKTAB= :KSFKTAB,"
                    +"KSFZTR= :KSFZTR,"
                    +"KSFHKSTKRS= :KSFHKSTKRS,"
                    +"KSFHKST= :KSFHKST,"
                    +"KSFAKSTKRS= :KSFAKSTKRS,"
                    +"KSFAKST= :KSFAKST,"
                    +"KSFPROGRP= :KSFPROGRP,"
                    +"KSFLFDNR= :KSFLFDNR,"
                    +"KSFAENZL= :KSFAENZL,"
                    +"KSFAENB= :KSFAENB,"
                    +"KSFAEND= :KSFAEND,"
                    +"KSFNEUB= :KSFNEUB,"
                    +"KSFNEUD= :KSFNEUD,"
                    +"KSFVRSATZ01= :KSFVRSATZ01,"
                    +"KSFVRSATZ02= :KSFVRSATZ02,"
                    +"KSFVRSATZ03= :KSFVRSATZ03,"
                    +"KSFVRSATZ04= :KSFVRSATZ04,"
                    +"KSFVRSATZ05= :KSFVRSATZ05,"
                    +"KSFBAS= :KSFBAS,"
                    +"KSFPROZ= :KSFPROZ,"
                    +"KSFSTUFE= :KSFSTUFE,"
                    +"KSFPMG01= :KSFPMG01,"
                    +"KSFPMG02= :KSFPMG02,"
                    +"KSFPMG03= :KSFPMG03,"
                    +"KSFPMG04= :KSFPMG04,"
                    +"KSFPMG05= :KSFPMG05,"
                    +"KSFPMG06= :KSFPMG06,"
                    +"KSFPMG07= :KSFPMG07,"
                    +"KSFPMG08= :KSFPMG08,"
                    +"KSFPMG09= :KSFPMG09,"
                    +"KSFPMG10= :KSFPMG10,"
                    +"KSFPMG11= :KSFPMG11,"
                    +"KSFPMG12= :KSFPMG12,"
                    +"KSFPLAN01= :KSFPLAN01,"
                    +"KSFPLAN02= :KSFPLAN02,"
                    +"KSFPLAN03= :KSFPLAN03,"
                    +"KSFPLAN04= :KSFPLAN04,"
                    +"KSFPLAN05= :KSFPLAN05,"
                    +"KSFPLAN06= :KSFPLAN06,"
                    +"KSFPLAN07= :KSFPLAN07,"
                    +"KSFPLAN08= :KSFPLAN08,"
                    +"KSFPLAN09= :KSFPLAN09,"
                    +"KSFPLAN10= :KSFPLAN10,"
                    +"KSFPLAN11= :KSFPLAN11,"
                    +"KSFPLAN12= :KSFPLAN12,"
                    +"KSFIST01= :KSFIST01,"
                    +"KSFIST02= :KSFIST02,"
                    +"KSFIST03= :KSFIST03,"
                    +"KSFIST04= :KSFIST04,"
                    +"KSFIST05= :KSFIST05,"
                    +"KSFIST06= :KSFIST06,"
                    +"KSFIST07= :KSFIST07,"
                    +"KSFIST08= :KSFIST08,"
                    +"KSFIST09= :KSFIST09,"
                    +"KSFIST10= :KSFIST10,"
                    +"KSFIST11= :KSFIST11,"
                    +"KSFIST12= :KSFIST12,"
                    +"KSFBEM= :KSFBEM,"
                    +"KSFFILLER= :KSFFILLER,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("KSFMANDANT", OracleType.NVarChar).Value = dwData["KSFMANDANT"].ToString(); 
          or1.Parameters.Add("KSFKTAB", OracleType.NVarChar).Value = dwData["KSFKTAB"].ToString(); 
          or1.Parameters.Add("KSFZTR", OracleType.NVarChar).Value = dwData["KSFZTR"].ToString(); 
          or1.Parameters.Add("KSFHKSTKRS", OracleType.NVarChar).Value = dwData["KSFHKSTKRS"].ToString(); 
          or1.Parameters.Add("KSFHKST", OracleType.NVarChar).Value = dwData["KSFHKST"].ToString(); 
          or1.Parameters.Add("KSFAKSTKRS", OracleType.NVarChar).Value = dwData["KSFAKSTKRS"].ToString(); 
          or1.Parameters.Add("KSFAKST", OracleType.NVarChar).Value = dwData["KSFAKST"].ToString(); 
          or1.Parameters.Add("KSFPROGRP", OracleType.NVarChar).Value = dwData["KSFPROGRP"].ToString(); 
          or1.Parameters.Add("KSFLFDNR", OracleType.NVarChar).Value = dwData["KSFLFDNR"].ToString(); 
          or1.Parameters.Add("KSFAENZL", OracleType.NVarChar).Value = dwData["KSFAENZL"].ToString(); 
          or1.Parameters.Add("KSFAENB", OracleType.NVarChar).Value = dwData["KSFAENB"].ToString(); 
          or1.Parameters.Add("KSFAEND", OracleType.NVarChar).Value = dwData["KSFAEND"].ToString(); 
          or1.Parameters.Add("KSFNEUB", OracleType.NVarChar).Value = dwData["KSFNEUB"].ToString(); 
          or1.Parameters.Add("KSFNEUD", OracleType.NVarChar).Value = dwData["KSFNEUD"].ToString(); 
          or1.Parameters.Add("KSFVRSATZ01", OracleType.NVarChar).Value = dwData["KSFVRSATZ01"].ToString(); 
          or1.Parameters.Add("KSFVRSATZ02", OracleType.NVarChar).Value = dwData["KSFVRSATZ02"].ToString(); 
          or1.Parameters.Add("KSFVRSATZ03", OracleType.NVarChar).Value = dwData["KSFVRSATZ03"].ToString(); 
          or1.Parameters.Add("KSFVRSATZ04", OracleType.NVarChar).Value = dwData["KSFVRSATZ04"].ToString(); 
          or1.Parameters.Add("KSFVRSATZ05", OracleType.NVarChar).Value = dwData["KSFVRSATZ05"].ToString(); 
          or1.Parameters.Add("KSFBAS", OracleType.NVarChar).Value = dwData["KSFBAS"].ToString(); 
          or1.Parameters.Add("KSFPROZ", OracleType.NVarChar).Value = dwData["KSFPROZ"].ToString(); 
          or1.Parameters.Add("KSFSTUFE", OracleType.NVarChar).Value = dwData["KSFSTUFE"].ToString(); 
          or1.Parameters.Add("KSFPMG01", OracleType.NVarChar).Value = dwData["KSFPMG01"].ToString(); 
          or1.Parameters.Add("KSFPMG02", OracleType.NVarChar).Value = dwData["KSFPMG02"].ToString(); 
          or1.Parameters.Add("KSFPMG03", OracleType.NVarChar).Value = dwData["KSFPMG03"].ToString(); 
          or1.Parameters.Add("KSFPMG04", OracleType.NVarChar).Value = dwData["KSFPMG04"].ToString(); 
          or1.Parameters.Add("KSFPMG05", OracleType.NVarChar).Value = dwData["KSFPMG05"].ToString(); 
          or1.Parameters.Add("KSFPMG06", OracleType.NVarChar).Value = dwData["KSFPMG06"].ToString(); 
          or1.Parameters.Add("KSFPMG07", OracleType.NVarChar).Value = dwData["KSFPMG07"].ToString(); 
          or1.Parameters.Add("KSFPMG08", OracleType.NVarChar).Value = dwData["KSFPMG08"].ToString(); 
          or1.Parameters.Add("KSFPMG09", OracleType.NVarChar).Value = dwData["KSFPMG09"].ToString(); 
          or1.Parameters.Add("KSFPMG10", OracleType.NVarChar).Value = dwData["KSFPMG10"].ToString(); 
          or1.Parameters.Add("KSFPMG11", OracleType.NVarChar).Value = dwData["KSFPMG11"].ToString(); 
          or1.Parameters.Add("KSFPMG12", OracleType.NVarChar).Value = dwData["KSFPMG12"].ToString(); 
          or1.Parameters.Add("KSFPLAN01", OracleType.NVarChar).Value = dwData["KSFPLAN01"].ToString(); 
          or1.Parameters.Add("KSFPLAN02", OracleType.NVarChar).Value = dwData["KSFPLAN02"].ToString(); 
          or1.Parameters.Add("KSFPLAN03", OracleType.NVarChar).Value = dwData["KSFPLAN03"].ToString(); 
          or1.Parameters.Add("KSFPLAN04", OracleType.NVarChar).Value = dwData["KSFPLAN04"].ToString(); 
          or1.Parameters.Add("KSFPLAN05", OracleType.NVarChar).Value = dwData["KSFPLAN05"].ToString(); 
          or1.Parameters.Add("KSFPLAN06", OracleType.NVarChar).Value = dwData["KSFPLAN06"].ToString(); 
          or1.Parameters.Add("KSFPLAN07", OracleType.NVarChar).Value = dwData["KSFPLAN07"].ToString(); 
          or1.Parameters.Add("KSFPLAN08", OracleType.NVarChar).Value = dwData["KSFPLAN08"].ToString(); 
          or1.Parameters.Add("KSFPLAN09", OracleType.NVarChar).Value = dwData["KSFPLAN09"].ToString(); 
          or1.Parameters.Add("KSFPLAN10", OracleType.NVarChar).Value = dwData["KSFPLAN10"].ToString(); 
          or1.Parameters.Add("KSFPLAN11", OracleType.NVarChar).Value = dwData["KSFPLAN11"].ToString(); 
          or1.Parameters.Add("KSFPLAN12", OracleType.NVarChar).Value = dwData["KSFPLAN12"].ToString(); 
          or1.Parameters.Add("KSFIST01", OracleType.NVarChar).Value = dwData["KSFIST01"].ToString(); 
          or1.Parameters.Add("KSFIST02", OracleType.NVarChar).Value = dwData["KSFIST02"].ToString(); 
          or1.Parameters.Add("KSFIST03", OracleType.NVarChar).Value = dwData["KSFIST03"].ToString(); 
          or1.Parameters.Add("KSFIST04", OracleType.NVarChar).Value = dwData["KSFIST04"].ToString(); 
          or1.Parameters.Add("KSFIST05", OracleType.NVarChar).Value = dwData["KSFIST05"].ToString(); 
          or1.Parameters.Add("KSFIST06", OracleType.NVarChar).Value = dwData["KSFIST06"].ToString(); 
          or1.Parameters.Add("KSFIST07", OracleType.NVarChar).Value = dwData["KSFIST07"].ToString(); 
          or1.Parameters.Add("KSFIST08", OracleType.NVarChar).Value = dwData["KSFIST08"].ToString(); 
          or1.Parameters.Add("KSFIST09", OracleType.NVarChar).Value = dwData["KSFIST09"].ToString(); 
          or1.Parameters.Add("KSFIST10", OracleType.NVarChar).Value = dwData["KSFIST10"].ToString(); 
          or1.Parameters.Add("KSFIST11", OracleType.NVarChar).Value = dwData["KSFIST11"].ToString(); 
          or1.Parameters.Add("KSFIST12", OracleType.NVarChar).Value = dwData["KSFIST12"].ToString(); 
          or1.Parameters.Add("KSFBEM", OracleType.NVarChar).Value = dwData["KSFBEM"].ToString(); 
          or1.Parameters.Add("KSFFILLER", OracleType.NVarChar).Value = dwData["KSFFILLER"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
